//
// Created by grg on 2020/8/4.
// Copyright (c) 2020 龚任根. All rights reserved.
//

#ifndef TEST_CPP_PROJECT_TEXTVIEW_H
#define TEST_CPP_PROJECT_TEXTVIEW_H

#include "IBlockPart.h"
#include "SDL2_ttf/SDL_ttf.h"
#include "stdlib.h"
//#include "string.h"

class TextView : public IBlockPart {
private:
    SDL_Surface *textSurface;
    SDL_Texture *texture;
    SDL_Rect src;
    SDL_Rect target = {0, 0, 100, 100};

public:
    TextView(TTF_Font *gFont, const char *text, SDL_Color &color) {
        textSurface = TTF_RenderText_Solid(gFont, text, color);
        texture = SDL_CreateTextureFromSurface(gContext->getRender(), textSurface);
    }

    ~TextView() {
        SDL_DestroyTexture(texture);
        SDL_FreeSurface(textSurface);
    }


public:
    void kill() override {
        delete this;
    }

protected:
    void event(const SDL_Event *event) override {

    }

    void draw() override {
        updateUI(texture, nullptr, &target);
    }

    void update() override {

    }

};


#endif //TEST_CPP_PROJECT_TEXTVIEW_H
